<template>
	<view class="content">
		<mescroll-uni class="my-mescroll" ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="rec-list">
			<!-- 跟进列表 -->
			<view class="activ-item" v-for="(item, index) in dataList" :key="index">
				<view class="user-info"  @click="showDetail(item)">
					<view class="left">
						<view class="head-box">
							in
						</view>
						<view class="info">
							<view class="name-box">
								<text class="name">{{item.nickName}}</text>
								<view class="btn-box">
									<view class="deal-btn un-deal">
										{{utils.getDictLabelName("customerVisitType",item.visitType)}}
									</view>
								</view> 
							</view>
							<text class="time">{{item.createTime}}</text>
						</view>
					</view>
					<view class="right">
						客户-跟进记录
					</view>
				</view>
				<view class="active-info">
					{{item.content}}
				</view>
				<view class="active-img"  @tap="previewImage(item.photos)">
					<image  v-if="item.photos!=null" v-for="(photo, index) in utils.photosToArr(item.photos)" class="img" :src="baseUrl+photo" mode="aspectFill"></image>
					 
				</view>
				<view class="custo-info"  @click="showDetail(item)">
					<image class="img" src="../../../static/images/icon_cust.png" mode="aspectFill"></image>
					<view class="text">客户-<text class="name">{{item.customerName}}</text></view>
				</view>
				<view class="follow-time">
					<image class="img" src="../../../static/images/icon_head.png" mode="aspectFill"></image>
					<text class="text">下次跟进时间：{{item.nextTime}}</text>
				</view>
			</view>
		</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
	import api from '@/api/api.js';
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				baseUrl:uni.getStorageSync('requestPath'),
				mescroll:undefined,
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					// onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					auto: true, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 1, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				dataList: [],
			}
		},
		onLoad() {
			// 修改顶部导航背景色
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: '#39b54a',
				animation: {
					duration: 400,
					timingFunc: 'easeIn'
				}
			})
		},
		methods: {
			// mescroll组件初始化的回调,可获取到mescroll对象
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				this.getMyCustomerVisitList(page);
			},
			getMyCustomerVisitList(page){
				var data = {page:page.num};
				var that=this;
				api.getMyCustomerVisitList(data).then(
					res => {
						if(res.code==200){
						 
							//设置列表数据
							if (page.num ==1) {
								that.dataList = res.data.list; 
								
							} else {
								that.dataList = that.dataList.concat(res.data.list);
								 
							}
							that.mescroll.endBySize(res.data.list.length, res.data.total);
							
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
							that.dataList = null;
							mescroll.endErr();
							// that.mescroll.endSuccess(0);
						}
					},
					rej => {}
				);
			},
			// 查看详情
			showDetail(item){
				uni.navigateTo({
					url: '../../customer/customDetail?customerId='+item.customerId+'&customerUserId='+item.customerUserId
				})
				 
			},
			 previewImage(photos){
			 	var photosArr=photos.split(",");
			 	var imgArr = [];
			 	photosArr.forEach(function(element) {
			 	   imgArr.push(uni.getStorageSync('requestPath')+element);
			 	});
			 	//预览图片
			 	uni.previewImage({
			 		urls: imgArr,
			 		current: imgArr[0]
			 	});
			 }
		}
	}
</script>

<style scoped lang="scss">
	.content{
		.rec-list{
			background: #fff;
			padding: 0 24upx;
			.activ-item{
				padding-bottom: 20upx;
				.user-info{
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 30upx 0;
					.left{
						display: flex;
						align-items: center;
						.head-box{
							width: 90upx;
							height: 90upx;
							line-height: 90upx;
							border-radius: 50%;
							background: #0aAC44;
							font-size: 28upx;
							color: #fff;
							text-align: center;
							margin-right: 20upx;
						}
						.info{
							height: 90upx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;
							.name-box{
								display: flex;
								align-items: center;
								.name{
									font-size: 28upx;
									color: #000;
									margin-right: 30upx;
								}
								.btn-box{
									.deal-btn{
										padding: 5upx 10upx;
										text-align: center;
										border-radius: 20upx;
										font-size: 24upx;
										&.deal{
											background: #0aAC44;
											color: #fff;
										}
										&.un-deal{
											background: #EFEFEF;
											color: #BDBDBD;
										}
									}
								}
							}
							.time{
								font-size: 28upx;
								color: #999;
							}
						}
					}
					.right{
						font-size: 24upx;
						color: #999;
					}
				}
				.active-info{
					display: flex;
					align-items: center;
					font-size: 32upx;
					color: #666;
					.name{
						font-size: 32upx;
						color: #2172FF;
					}
				}
				.active-img{
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					margin-top: 20upx;
					.img{
						width: 31.33%;
						height: 200upx;
						margin-right: 2%;
						margin-bottom: 20upx;
						&:nth-child(3n){
							margin-right: 0;
						}
					}
				}
				.follow-time{
					display: flex;
					align-items: center;
					margin-top: 20upx;
					.img{
						width: 30upx;
						height: 30upx;
					}
					.text{
						font-size: 28upx;
						color: #999;
						margin-left: 20upx;
					}
				}
				.custo-info{
					display: flex;
					align-items: center;
					margin-top: 20upx;
					.img{
						width: 30upx;
						height: 30upx;
					}
					.text{
						font-size: 28upx;
						color: #333;
						margin-left: 20upx;
						.name{
							color: #2362FB;
						}
					}
				}
			}
		}
	}
</style>
